//
//  FANHomeCell.swift
//  Weibo - Swift
//
//  Created by user on 16/4/20.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit
import SnapKit

let FANNameLabelFontSize:CGFloat = 14

let FANTimeLabelFontSize:CGFloat = 11

let FANSourseLabelFontSize:CGFloat = 11

let FANMargin:CGFloat = 10

let FANIconImageViewWH:CGFloat = 35

let FANStatusCellContentFontSize:CGFloat = 15

let FANStatusCellBottomViewH:CGFloat = 35

class FANHomeCell: UITableViewCell {
    
    var toolBarCon:Constraint?
    
    var dataViewModel:FANDataViewModel?{
        
        didSet{
            
            originalView.dataViewModel = dataViewModel
            
            toolBarCon?.uninstall()
            
            //有转发
            if dataViewModel?.status?.retweeted_status != nil{
                
                retweetView.dataViewModel = dataViewModel
                
                retweetView.hidden = false
                
                toolBar.snp_updateConstraints(closure: { (make) -> Void in
                    
                    toolBarCon = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
            }else{
                
                retweetView.hidden = true
                
                toolBar.snp_updateConstraints(closure: { (make) -> Void in
                    
                    toolBarCon = make.top.equalTo(originalView.snp_bottom).constraint
                })
            }
            
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        selectionStyle = .None
        
        contentView.addSubview(originalView)
        contentView.addSubview(toolBar)
        contentView.addSubview(retweetView)
        
        backgroundColor = UIColor(white: 210/255, alpha: 1)

        
        originalView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentView).offset(FANMargin)
            
            make.leading.trailing.equalTo(contentView)
            
//            make.height.equalTo(120)
        }
        
        toolBar.snp_makeConstraints { (make) -> Void in
            
            toolBarCon = make.top.equalTo(retweetView.snp_bottom).constraint
            
//            make.bottom.trailing.leading.equalTo(contentView)
            make.trailing.leading.equalTo(contentView)
        }
        
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(self)
            make.bottom.equalTo(toolBar)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(originalView.snp_bottom)

            make.leading.trailing.equalTo(originalView)
            
        }
        
        
    }

    private lazy var retweetView:FANRetweetView = FANRetweetView()
    
    private lazy var originalView:FANOriginalView = FANOriginalView()
    
    private lazy var toolBar:FANStatusToolBar = FANStatusToolBar()

}
